package com.ym.pms.service.impl;

import com.ym.pms.service.IFileUploadService;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.UUID;

/**
 * @Author: xybh
 * @Description:
 * @Date: Created in 21:49 2020/12/14
 * @Modified:
 */
@Service
public class FileUploadServiceImpl implements IFileUploadService {
    @Override
    public String fileUploadInServer(MultipartFile upload, String path) throws IOException {
        File file = new File(path);
        if(!file.exists()){
            file.mkdirs();
        }
        //获取上传文件的名称
        String filename = upload.getOriginalFilename();
        //把文件的名称设置为唯一值,UUID
        String uuid = UUID.randomUUID().toString().replace("-", "");
        filename = uuid + "_" + filename;
        //完成文件上传
        upload.transferTo(new File(path, filename));
        return path+filename;
    }
}
